//  MainViewController.m
//  maocuhuiOASystem
//
//  Created by michael on 16/3/20.
//  Copyright © 2016年 czd. All rights reserved.
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

#define IS_PAD (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad)
#import "xiebanViewController.h"
#import "liuzhuanViewController.h"
#import "zhibanViewController.h"
#import "MeetingViewController.h"
#import "webtViewController.h"
#import "xxxViewController.h"
#import "MYCycleView.h"
#import "nbViewController.h"
#import "ldViewController.h"
#import "hyViewController.h"
#import "dengjiTableViewController.h"
#import "gwchaxunViewController.h"
#import "dzggViewController.h"
#import "fwclViewController.h"
#import "ViewController3.h"
#import "UIViewController+MMDrawerController.h"
#import "fwdjViewController.h"
#import "MainViewController.h"
#import "OALoginViewController.h"
#import "itemcell.h"
#import "OABaseNavViewController.h"
#import "ComingworkongController.h"
#import "emailViewController.h"
#import "iseditViewController.h"
#import "overworkingViewController.h"
#import "comingthingViewController.h"
#import "ideitworkViewController.h"
#import "workedViewController.h"
#import "OANewInViewController.h"
#import "OANewSendViewController.h"
#import "NotonewsViewController.h"
#import "webViewController.h"
#import "OAAddressViewController.h"
#import "OASMSViewController.h"
#import "MainViewCell.h"
#import "BaseModel.h"
#import "ReceieveViewController.h"
#import "AuthHelper.h"
#import "OASendMessageViewController.h"
#import "OAInBoxViewController.h"
#import "ipadmainviewcell.h"
#import "ipadloginViewController.h"
#import "glViewController.h"
#define kWB_Login_NotificationName @"requestdata"
#define KSlength  KScreenHeight-46-64-20
@interface HomeModel : BaseModel

@property(nonatomic,copy)NSString *  exchange;
@property(nonatomic,copy)NSString *  ksmail;
@property(nonatomic,copy)NSString *  mail;
@property(nonatomic,copy)NSString *  offiece;
@property(nonatomic,copy)NSString *  whetherExchange;
@property(nonatomic,copy)NSString *  whetherSms;
@property(nonatomic,copy)NSString * read;
@end
@implementation HomeModel


@end
@interface MainViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,SangforSDKDelegate>
@property (nonatomic, strong) MYCycleView *cycleView;

@property (nonatomic,strong) UIButton *button1;
@property (nonatomic,strong) UIButton *button2;
@property(nonatomic,strong)NSMutableArray * contentArray;

@property(nonatomic,strong)HomeModel * homeModel;
@property(nonatomic,strong)NSMutableArray * originalData;
@property(nonatomic,strong)NSArray * array;
@property (nonatomic, strong) AuthHelper *helper;
@end

@implementation MainViewController
static NSString * const reuseIdentifier = @"CellIdentifier";
-(NSMutableArray*)contentArray{
    if (_contentArray == nil) {
        _contentArray = [NSMutableArray array];
    }
    return _contentArray;
}

- (void)viewDidLoad {
short port = 443;                        //vpn设备端口号，一般为443
NSString *vpnIp =    @"122.224.123.170";  //vpn设备IP地址
//    self.helper = [[AuthHelper alloc] initWithHostAndPort:vpnIp port:port delegate:self];

    [super viewDidLoad];
    if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {
//        self.automaticallyAdjustsScrollViewInsets = NO;
}

// 更改标题的颜色
//UIImageView *view = [[UIImageView alloc]initWithFrame:self.view.frame];
//view.image = [UIImage imageNamed:@"3、首页-3"];
//[self.view addSubview:view];
self.view.backgroundColor = [UIColor whiteColor];
UIView *view = [[UIView alloc]initWithFrame:self.view.frame];

UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.1];
view.backgroundColor = myColor;
[self.view addSubview:view];
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:

[UIColor whiteColor],NSForegroundColorAttributeName, nil];
 
[self.navigationController.navigationBar setTitleTextAttributes:attributes];
self.title = @"嘉兴市市场管理局";
 self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
 
 
 
 
   [self _backbutton];
       self.cycleView = [[MYCycleView alloc] initWithFrame:CGRectMake(0,kTopHeight, [UIScreen mainScreen].bounds.size.width, (KScreenHeight-kTopHeight)*1/3)];

//    当imageArray.cout为1时，不轮播，相当于imageView;
    self.cycleView.imageArray = @[@"pic_01",@"pic_02",@"pic_03"];
//    设置轮播时间，小于0时逆向，大于0时正向，等于0是不自动轮播
    self.cycleView.second = 2;
////    设置pageControl未选中indicator的颜色
    self.cycleView.pageIndicatorColor = [UIColor whiteColor];
////    设置pageControl当前indicator的颜色
    self.cycleView.currentIndicatorColor = [UIColor yellowColor];
    
    self.cycleView.bannerClick = ^(NSInteger index) {
        
        NSLog(@"点击了%zd",index);
        
    };
    
    [self.view addSubview:self.cycleView];
 UICollectionViewFlowLayout *followLayout = [[UICollectionViewFlowLayout alloc]init];
     followLayout.itemSize = CGSizeMake((KScreenWidth-3)/ 4,(self.view.height-kTopHeight-_cycleView.height-49 -3)/ 4 );

self.collectionView  = [[UICollectionView alloc]initWithFrame:CGRectMake(0,_cycleView.bottom, KScreenWidth, self.view.height-kTopHeight-49-_cycleView.height) collectionViewLayout:followLayout];
[self.view addSubview :_collectionView];
_collectionView.backgroundColor = [UIColor clearColor];
_collectionView.scrollEnabled = NO;
_collectionView.delegate = self;
_collectionView.dataSource = self;
    [_collectionView registerNib:[UINib nibWithNibName:@"MainViewCell" bundle:nil] forCellWithReuseIdentifier:@"FansCellId"];
    [_collectionView registerNib:[UINib nibWithNibName:@"ipadmainviewcell" bundle:nil] forCellWithReuseIdentifier:@"ipadId"];
    followLayout.minimumLineSpacing =1;
        followLayout.minimumInteritemSpacing =1;
// 判断版本
[self upApp];
//定时器
     dispatch_async(dispatch_get_global_queue(0, 0), ^{
        _timer = [NSTimer scheduledTimerWithTimeInterval:300 target:self selector:@selector(news) userInfo:nil repeats:YES];
        // 开启当前线程
        [[NSRunLoop currentRunLoop] run];
    });

      //修改返回按钮的颜色和字体
  self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
   UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
[self requestname];
}
- (void)requestname{

[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array = @[@{@"userId":userId}];
    [HttpTools requestWithURL:Kexchmain arrays:array method:@"getFullName" success:^(id JSON) {
    NSLog(@"=====%@",JSON);
    NSString * name = JSON[@"fullname"];
   NSString* newname = [NSString stringWithFormat:@"%@(ios)",name];
                        [[NSUserDefaults standardUserDefaults] setObject:newname forKey:@"realname"];

        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
       
                } failure:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    }];




}
- (void)upApp{
 //获取app版本号
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *appVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    
    
    NSArray *array = @[@{@"veseion":appVersion}];

[HttpTools requestWithURL:KExchmain arrays:array method:@"updateDown" success:^(id JSON) {
if (![JSON isKindOfClass:[NSDictionary class]]) {
    [self.view makeToast:@"服务器出错!"];
}
//if ([JSON isEqualToString:@"-1044"]) {
//    [self.view makeToast:@"服务器出错!"];
//}
else{
         NSArray *tempArray  = JSON[@"data"];
        NSDictionary * dict = [tempArray firstObject];
            NSString *url = dict[@"downlink"];
        NSString *index = dict[@"result"];
    
    
    if ([index isEqualToString:@"1"]) {
            
// 提示更新
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"更新" message:@"程序已经更新，请卸载完以前的版本，再重新下载" preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel  handler:^(UIAlertAction * _Nonnull action) {
        
                  [_helper logoutVpn];
     UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

    OALoginViewController * loginVC =  [storyBoard instantiateViewControllerWithIdentifier:@"LoginVC"];
             loginVC.type = @"1";

    self.view.window.rootViewController = loginVC;
                
            }];

            UIAlertAction *action = [UIAlertAction actionWithTitle:@"更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                if (url.length != 0) {
                    
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

                }
                
            }];
            
            [alert addAction:cancelAction];
            [alert addAction:action];
            
            [self presentViewController:alert animated:YES completion:nil];
            
            
       }
            
        }

    }failure:^(NSError *error) {
        
    }];

    

}

- (void)dealloc
{
    // 移除通知
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kWB_Login_NotificationName object:nil];
    }
// 使用storyboard创建的控制调用的初始化方法
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        // 注册通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(news) name:kWB_Login_NotificationName object:nil];
       
        
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated{
    self.cycleView.second = 2;
    short port = 443;                        //vpn设备端口号，一般为443
NSString *vpnIp =    @"220.191.244.22";
 if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"shoushi"] isEqualToString:@"Y"]) {
     
//        self.helper = [[AuthHelper alloc] initWithHostAndPort:vpnIp port:443 delegate:self];
//        [self.helper setAuthParam:@AUTO_LOGIN_OFF_KEY param:@"true"];
     
//        [self updateApp];

    }else{
//            self.helper = [[AuthHelper alloc] initWithHostAndPort:vpnIp port:443 delegate:self];

    
    }


[self news];
}
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
//    停止轮播
    self.cycleView.second = 0;
}
- (void)news{
 NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray *  array = @[@{@"userId":userId}];;
    [HttpTools requestWithURL:KExchmain arrays:array method:KHomePqwoiunu success:^(id JSON) {
    if (![JSON isKindOfClass:[NSDictionary class]]) {
    [self.view makeToast:@"服务器出错!"];
}else{
    NSLog(@"%@",JSON);
    
    
    
         NSArray *tempArray  = JSON[@"data"];
        NSDictionary * dict = [tempArray firstObject];
 
        self.homeModel = [[HomeModel alloc] initWitDictionary:dict];
                    [self setupSubView];

            [self.collectionView reloadData];
            }

    } failure:^(NSError *error) {
        
    }];
  
}
-(void)setupSubView{
if ([self.homeModel.whetherExchange isEqualToString:@"0"]) {  NSString * filePath =  [[NSBundle mainBundle] pathForResource:@"mainList1" ofType:@"plist"];
    self.originalData = [NSMutableArray arrayWithContentsOfFile:filePath];
    [self.contentArray addObjectsFromArray:self.originalData];
    self.contentArray = [self.originalData mutableCopy];
    [self.collectionView reloadData];
    }
  else { NSString * filePath =  [[NSBundle mainBundle] pathForResource:@"mainList" ofType:@"plist"];
    self.originalData = [NSMutableArray arrayWithContentsOfFile:filePath];
    [self.contentArray addObjectsFromArray:self.originalData];
    self.contentArray = [self.originalData mutableCopy];
    [self.collectionView reloadData];}
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.contentArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if(IS_IPHONE){
MainViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FansCellId" forIndexPath:indexPath];

    NSDictionary * dict = self.contentArray[indexPath.item];
    cell.dict = dict;
    if ([dict[@"title"] isEqualToString:@"待办公文"]) {
        [cell.btnCount setTitle:self.homeModel.offiece forState:UIControlStateNormal];
        if ([self.homeModel.offiece integerValue] !=0) {
            cell.btnCount.hidden = NO;
        }else{
            cell.btnCount.hidden = YES;
        }
    }
   else if ([dict[@"title"] isEqualToString:@"待收文件"]) {
        [cell.btnCount setTitle:self.homeModel.exchange forState:UIControlStateNormal];
        if ([self.homeModel.exchange integerValue] !=0) {
            cell.btnCount.hidden = NO;
        }else{
            cell.btnCount.hidden = YES;
        }
    } else if ([dict[@"title"] isEqualToString:@"待阅公文"]) {
        [cell.btnCount setTitle:self.homeModel.read forState:UIControlStateNormal];
        if ([self.homeModel.read integerValue] !=0) {
            cell.btnCount.hidden = NO;
        }else{
            cell.btnCount.hidden = YES;
        }
    } else{
        cell.btnCount.hidden = YES;
    }
    [cell layoutIfNeeded];
    return cell;

}else{
ipadmainviewcell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ipadId" forIndexPath:indexPath];

    NSDictionary * dict = self.contentArray[indexPath.item];
    cell.dict = dict;
if ([dict[@"title"] isEqualToString:@"待办公文"]) {
        [cell.btnCount setTitle:self.homeModel.offiece forState:UIControlStateNormal];
        if ([self.homeModel.offiece integerValue] !=0) {
            cell.btnCount.hidden = NO;
        }else{
            cell.btnCount.hidden = YES;
        }
    } 
    
   else  if ([dict[@"title"] isEqualToString:@"待收文件"]) {
        [cell.btnCount setTitle:self.homeModel.exchange forState:UIControlStateNormal];
        if ([self.homeModel.exchange integerValue] !=0) {
            cell.btnCount.hidden = NO;
        }else{
            cell.btnCount.hidden = YES;
        }
    } else if ([dict[@"title"] isEqualToString:@"待阅公文"]) {
        [cell.btnCount setTitle:self.homeModel.read forState:UIControlStateNormal];
        if ([self.homeModel.read integerValue] !=0) {
            cell.btnCount.hidden = NO;
        }else{
            cell.btnCount.hidden = YES;
        }
    }else{
        cell.btnCount.hidden = YES;
    }
 
    [cell layoutIfNeeded];
    return cell;


}


}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
// NSLog(@"cell #%ld was selected", (long)indexPath.row);
 NSDictionary * dict =  self.contentArray[indexPath.item];
  
   UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    if ([dict[@"title"] isEqualToString:@"收文管理"]) {
//    int ssl_vpn_logout();



      ReceieveViewController *comvc =(ReceieveViewController *) [self.storyboard instantiateViewControllerWithIdentifier:@"Receieve"];
      comvc.string = self.homeModel.exchange;
                                          comvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:comvc animated:YES];
    
    }
    if ([dict[@"title"] isEqualToString:@"发文管理"]) {
   fwdjViewController *comvc =  [[fwdjViewController alloc]init];
   
//           comvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:comvc animated:YES];
    }

       if ([dict[@"title"] isEqualToString:@"待办公文"]) {
   ComingworkongController *comvc =(ComingworkongController *) [storyBoard instantiateViewControllerWithIdentifier:@"comvc"];
//     

                                             comvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:comvc animated:YES];
    }
     if ([dict[@"title"] isEqualToString:@"待阅公文"]) {

FSWaitReceiveController * dueInVC = (FSWaitReceiveController*)[storyBoard instantiateViewControllerWithIdentifier:@"WaitReceive"];
 dueInVC.hidesBottomBarWhenPushed= YES;
    dueInVC.vcType = WaitForReadType;
        [self.navigationController pushViewController:dueInVC animated:YES];
}
if ([dict[@"title"] isEqualToString:@"已阅公文"]) {

FSWaitReceiveController * dueInVC = (FSWaitReceiveController*)[storyBoard instantiateViewControllerWithIdentifier:@"WaitReceive"];
 dueInVC.hidesBottomBarWhenPushed= YES;
    dueInVC.vcType = EditForReadType;
        [self.navigationController pushViewController:dueInVC animated:YES];
}
  if ([dict[@"title"] isEqualToString:@"待收文件"]) {UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

FSWaitReceiveController * dueInVC = (FSWaitReceiveController*)[storyBoard instantiateViewControllerWithIdentifier:@"WaitReceive"];
 dueInVC.hidesBottomBarWhenPushed= YES;
    dueInVC.vcType = WaitForSignType;
        [self.navigationController pushViewController:dueInVC animated:YES];
}
  if ([dict[@"title"] isEqualToString:@"已收文件"]) {
//  UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
FSWaitReceiveController * dueInVC = (FSWaitReceiveController*)[storyBoard instantiateViewControllerWithIdentifier:@"WaitReceive"];
 dueInVC.hidesBottomBarWhenPushed= YES;
    dueInVC.vcType = AlreadySignType;
        [self.navigationController pushViewController:dueInVC animated:YES];
}

  if ([dict[@"title"] isEqualToString:@"公文发件箱"]) {
//  UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
FSWaitReceiveController * dueInVC = (FSWaitReceiveController*)[storyBoard instantiateViewControllerWithIdentifier:@"WaitReceive"];
 dueInVC.hidesBottomBarWhenPushed= YES;
    dueInVC.vcType = SenderSinType;
        [self.navigationController pushViewController:dueInVC animated:YES];
}

    
     if ([dict[@"title"] isEqualToString:@"通知公告"]) {
     dzggViewController *comvc = [[dzggViewController alloc]init];
     comvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:comvc animated:YES];
    }

if ([dict[@"title"] isEqualToString:@"文件查询"]) {
     gwchaxunViewController *comvc = [[gwchaxunViewController alloc]init];
                                             comvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:comvc animated:YES];
    }
       if ([dict[@"title"] isEqualToString:@"管理制度"]) {
     glViewController *comvc = [[glViewController alloc]init];
     comvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:comvc animated:YES];
    }
      if ([dict[@"title"] isEqualToString:@"流转监控"]) {
     liuzhuanViewController *comvc = [[liuzhuanViewController alloc]init];
     comvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:comvc animated:YES];
    }

    if ([dict[@"title"] isEqualToString:@"已办公文"]) {
//  iseditViewController *isedvc =(iseditViewController *) [storyBoard instantiateViewControllerWithIdentifier:@"isedit"];
iseditViewController *isedvc = [[iseditViewController alloc]init];
isedvc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:isedvc animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"办结公文"]) {
   overworkingViewController *overvc = (overworkingViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"over"];
    [self.navigationController pushViewController:overvc animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"待办事项"]) {
   comingthingViewController *comthvc = (comingthingViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"comingthing"];
       [self.navigationController pushViewController:comthvc animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"已办事项"]) {
   ideitworkViewController *ideitvc = (ideitworkViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"ideit"];
    [self.navigationController pushViewController:ideitvc animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"办结事项"]) {
workedViewController *worked = (workedViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"worked"];
    [self.navigationController pushViewController:worked animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"通知通告"]) {
     NotonewsViewController *notonews = (NotonewsViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"notonews"];
    [self.navigationController pushViewController:notonews animated:YES];    }
    if ([dict[@"title"] isEqualToString:@"电子邮件"]) {
    ViewController3 *email = [[ViewController3 alloc]init];
//   emailViewController  *email = (emailViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"email"];
   email.read = self.homeModel.mail ;

    [self.navigationController pushViewController:email animated:YES];
    }
    
   if ([dict[@"title"] isEqualToString:@"收件箱"]) {
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

 OAInBoxViewController *invc = (OAInBoxViewController *) [storyBoard instantiateViewControllerWithIdentifier:@"inbox"];
    invc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:invc animated:YES];

NSLog(@"33");
}
 if ([dict[@"title"] isEqualToString:@"发件箱"]) {
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

NSLog(@"22");
OASendMessageViewController *sendvc = (OASendMessageViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"send"];
        sendvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:sendvc animated:YES];

}
   
    
    
    
    if ([dict[@"title"] isEqualToString:@"最新收文"]) {
//OANewInViewController *oAnewView =  (OANewInViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"OANewInView"];
//   //OANewInView
//        oAnewView.hidesBottomBarWhenPushed = YES;
//
//    [self.navigationController pushViewController:oAnewView animated:YES];
dengjiTableViewController *VC= [[dengjiTableViewController alloc]init];
 VC.hidesBottomBarWhenPushed= YES;

VC.method = @"swregbookPage";
[self.navigationController pushViewController:VC animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"最新发文"]) {
//   OANewSendViewController *oAnewSend = (OANewSendViewController *)
//   [self.storyboard instantiateViewControllerWithIdentifier:@"OANewIn"];
//        oAnewSend.hidesBottomBarWhenPushed = YES;
//
//    [self.navigationController pushViewController:oAnewSend animated:YES];
    dengjiTableViewController *VC= [[dengjiTableViewController alloc]init];
VC.method = @"regbookPage";
 VC.hidesBottomBarWhenPushed= YES;

[self.navigationController pushViewController:VC animated:YES];

    }
    if ([dict[@"title"] isEqualToString:@"通讯录"]) {
   OAAddressViewController * addressVC = (OAAddressViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"AddressVCID"];
        [self.navigationController pushViewController:addressVC animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"短信平台"]) {
   OASMSViewController *smvc = (OASMSViewController *)[ self.storyboard instantiateViewControllerWithIdentifier:@"SMSVCID"];
    [self.navigationController pushViewController:smvc animated:YES];
    }
 if ([dict[@"title"] isEqualToString:@"司法厅专网"]) {
  webtViewController *webvc = [[webtViewController alloc]init];
  webvc.url = @"http://59.202.29.217";
  


[self.navigationController pushViewController:webvc  animated:YES];
  }
    if ([dict[@"title"] isEqualToString:@"门户网站"]) {
   webtViewController *webvc = [[webtViewController alloc]init];
   webvc.url = @"http://www.jiaxingaic.gov.cn";
//    webvc.url = @"http://59.202.29.222/zjssft/zyzx/zbarrange.nsf/4ef0125724e329f0482581bf00264eed/0ff176007aed4ec3482581c000155701?OpenDocument";

[self.navigationController pushViewController:webvc  animated:YES];

    }
        if ([dict[@"title"] isEqualToString:@"值班查询"]) {
   zhibanViewController *webvc = [[zhibanViewController alloc]init];
//   webvc.url = @"http://www.zjsft.gov.cn";
[self.navigationController pushViewController:webvc  animated:YES];

    }
    if ([dict[@"title"] isEqualToString:@"一周工作"]) {
xxxViewController *worked = [[xxxViewController alloc]init];
    [self.navigationController pushViewController:worked animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"拟办工作"]) {
nbViewController *worked = [[nbViewController alloc]init];
    [self.navigationController pushViewController:worked animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"会议管理"]) {
MeetingViewController *worked = [[MeetingViewController alloc]init];
 worked.hidesBottomBarWhenPushed= YES;

    [self.navigationController pushViewController:worked animated:YES];
    }
    
    
   }


- (void)_backbutton{
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"退出"style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonAction:)];

                     self.navigationItem.rightBarButtonItem = item1;
 


     UIBarButtonItem * rightItem1  = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"3、首页-更多"] style:UIBarButtonItemStylePlain target:self action:@selector(createNewSMSAction)];
     UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];

   UIButton *liftButton = [UIButton buttonWithType:UIButtonTypeCustom];
liftButton.frame = CGRectMake(0, 0,30,30);
 [contentView addSubview:liftButton];

//登录页-logo
[liftButton setImage:[UIImage imageNamed:@"登录页-logo"] forState:UIControlStateDisabled];
UIBarButtonItem *rightItem2 = [[UIBarButtonItem alloc] initWithCustomView:contentView];
 liftButton.enabled = NO;
//       [self.navigationItem setLeftBarButtonItem:rightItem1];

   
 
    [self.navigationItem setLeftBarButtonItems:@[rightItem1,rightItem2]];

    
}
-(void)createNewSMSAction{
    
     [self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];   

    
}
- (void)makeview{

 NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray *  array = @[@{@"userId":userId}];;
    [HttpTools requestWithURL:KExchmain arrays:array method:KHomePqwoiunu success:^(id JSON) {
        NSArray *tempArray  = JSON[@"data"];
        NSDictionary * dict = [tempArray firstObject];
        self.homeModel = [[HomeModel alloc] initWitDictionary:dict];
        [self setupSubView];
    } failure:^(NSError *error) {
        
    }];
}
- (void) onCallBack:(const VPN_RESULT_NO)vpnErrno authType:(const int)authType
{short port = 443;                        //vpn设备端口号，一般为443
NSString *vpnIp =    @"220.191.244.22";  //vpn设备IP地址
NSString *userName = @"oa2";             //用户名认证的用户名
NSString *password = @"a1a1a1";                //用户名认证的密码

NSString *certName = @"";     //导入证书名字，如果服务端没有设置证书认证可以不设置
NSString *certPwd1 =  @"";          //证书密码，如果服务端没有设置证书
    switch (vpnErrno)
    {
        case RESULT_VPN_INIT_FAIL:
            NSLog(@"Vpn Init failed!");
            break;
            
        case RESULT_VPN_AUTH_FAIL:
            [self.helper clearAuthParam:@SET_RND_CODE_STR];
            NSLog(@"Vpn auth failed!");
            break;
            
        case RESULT_VPN_INIT_SUCCESS:
            NSLog(@"Vpn init success!");
            //设置认证参数 用户名和密码以数值map的形式传入
            [self.helper setAuthParam:@PORPERTY_NamePasswordAuth_NAME param:userName];
            [self.helper setAuthParam:@PORPERTY_NamePasswordAuth_PASSWORD param:password];
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"shoushi"] isEqualToString:@"Y"]) {

            [self.helper loginVpn:SSL_AUTH_TYPE_PASSWORD];
}
            break;
        case RESULT_VPN_AUTH_SUCCESS:
            [self startOtherAuth:authType];
            break;
        case RESULT_VPN_AUTH_LOGOUT:
            NSLog(@"Vpn logout success!");
            break;
        case RESULT_VPN_OTHER:
            if (VPN_OTHER_RELOGIN_FAIL == (VPN_RESULT_OTHER_NO)authType) {
                NSLog(@"Vpn relogin failed, maybe network error");
            }
            break;
            
        case RESULT_VPN_NONE:
            break;
            
        default:
            break;
    }
}

- (void) startOtherAuth:(const int)authType
{
short port = 443;                        //vpn设备端口号，一般为443
NSString *vpnIp =    @"220.191.244.22";  //vpn设备IP地址
NSString *userName = @"oa2";             //用户名认证的用户名
NSString *password = @"a1a1a1";                //用户名认证的密码

NSString *certName = @"";     //导入证书名字，如果服务端没有设置证书认证可以不设置
NSString *certPwd1 =  @"";          //证书密码，如果服务端没有设置证书
    NSArray *paths = nil;
    switch (authType)
    {
        case SSL_AUTH_TYPE_CERTIFICATE:
            paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                        NSUserDomainMask, YES);
            
            if (nil != paths && [paths count] > 0)
            {
                NSString *dirPaths = [paths objectAtIndex:0];
                NSString *authPaths = [dirPaths stringByAppendingPathComponent:certName];
                NSLog(@"PATH = %@",authPaths);
                [self.helper setAuthParam:@CERT_P12_FILE_NAME param:authPaths];
                [self.helper setAuthParam:@CERT_PASSWORD param:certPwd1];
            }
            NSLog(@"Start Cert Auth!!!");
            break;
            
        case SSL_AUTH_TYPE_PASSWORD:
            NSLog(@"Start Password Name Auth!!!");
            [self.helper setAuthParam:@PORPERTY_NamePasswordAuth_NAME param:userName];
            [self.helper setAuthParam:@PORPERTY_NamePasswordAuth_PASSWORD param:password];
            
            break;
        case SSL_AUTH_TYPE_NONE:
            NSLog(@"Auth success!!!");
                    [self makeview];
//            [self upApp];

            return;
        default:
            NSLog(@"Other failed!!!");
            return;
    }
    [self.helper loginVpn:authType];
}
- (void)rightButtonAction:(UIButton *)button {

 UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:nil message:@"是否退出移动办公" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//    if (buttonIndex == 1)
//    {
//    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"auto"];
//    if (![[NSUserDefaults standardUserDefaults] objectForKey:@"remember"])
//    {
//    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"remember"];
//    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"userId"];
//    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"pwdId"];
//    }
//          // [[NSUserDefaults standardUserDefaults] setObject:@(NO) forKey:@"remember"];
//
//       OALoginViewController * loginVC = (OALoginViewController*) [self.storyboard instantiateViewControllerWithIdentifier:@"LoginVC"];
//        UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
//        self.view.window.rootViewController = nav;
//        nav.navigationBar.hidden = YES;
//    }
if (buttonIndex == 1){
 [_helper logoutVpn];
    UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
if (IS_IPHONE) {
 OALoginViewController * loginVC =  [storyBoard instantiateViewControllerWithIdentifier:@"LoginVC"];
     [[NSUserDefaults standardUserDefaults] setObject:@"N" forKey:@"autoLogin"];
     loginVC.type = @"1";
    self.view.window.rootViewController = loginVC;
}else{
    ipadloginViewController * loginVC = [storyBoard instantiateViewControllerWithIdentifier:@"ipadLoginVC"];
     [[NSUserDefaults standardUserDefaults] setObject:@"N" forKey:@"autoLogin"];

        UINavigationController * navVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
                        loginVC.navigationController.navigationBar.hidden = YES;

    self.view.window.rootViewController = loginVC;

}

}
}
@end
